package com.powernode.controller;

import com.powernode.api.pojo.BaseInfo;
import com.powernode.api.pojo.ProductData;
import com.powernode.api.service.BaseInfoService;
import com.powernode.api.service.ProductInfoService;
import com.powernode.resp.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "盈利宝平台基本信息")
@RestController
public class IndexController {
    /* 前端给我什么 参数    执行干什么要的 业务逻辑   返回什么样的数据 */

    /*注入的实现类 来自 远程的服务  提供者*/
    @DubboReference(interfaceClass = BaseInfoService.class,version = "1.0.0")
    private BaseInfoService baseInfoService;


    @DubboReference(interfaceClass = ProductInfoService.class,version = "1.0.0")
    private ProductInfoService productInfoService;

    @ApiOperation(value = "平台三个数据",notes = "详细描述")
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "地址错误"),
            @ApiResponse(code = 500,message = "服务器异常"),
            @ApiResponse(code = 403,message = "没有权限"),
            @ApiResponse(code = 400,message = "参数转换失败")
    })
    @GetMapping("/v1/base/info")
    public Result getBaseInfo(){
        Result result = Result.SUCCESS();
        /*远程服务调用  接口  获取  BaseInfo*/
        BaseInfo baseInfo = baseInfoService.queryBaseInfo();
        /*将baseinfo存入 result*/
        result.setObject(baseInfo);
        return  result;
    }

    @ApiOperation("三个集合")
    @GetMapping("/v1/base/products")
    public Result getIndexProductData(){
        Result result = Result.SUCCESS();
        /*获取 三个 集合 并 存入 result*/
        ProductData productData = productInfoService.queryIndexProductList();
        result.setObject(productData);
        return result;
    }
}
